layui.use(['jquery','table','layer','laydate'],function () {
    var $ = layui.jquery;
    var table = layui.table;
    var layer = layui.layer;
    var laydate = layui.laydate;

    var userIdd = localStorage.getItem("userId");
    var trueName = localStorage.getItem("trueName");
    var account = localStorage.getItem("account");
    var userName = localStorage.getItem("userName");

    laydate.render({
        elem: "#createDate",
        type: "date",
        tigger: "click"
    });

    selectJsApplicant("","","");
    function selectJsApplicant(roleName,createDate,type) {
        table.render({
            elem:"#root",
            url:"/JsApplicant/selectJsAuditLog?roleName="+roleName+"&createDate="+createDate+"&type="+type,
            defaultToolbar: ['','',''],
            cellHeight:57,
            page:true,
            limit:10,
            limits:[10,15,20],
            size: 'lg',
            cols:[[
                {type:"checkbox",align:"center"},
                {type:"numbers",title:"序号",align:"center"},
                {field:"roleName",title:"创作者名称",align:"center"},
                {field:"position",title:"申请职务",align:"center"},
                {field:"createDate",title:"申请时间",align:"center"},
                {field:"type",title:"申请状态",align:"center",templet:function (data) {
                        if(data.type=="1"){
                            return "待审核";
                        }else if(data.type=="2"){
                            return "已通过";
                        }else{
                            return "已驳回";
                        }
                    }},
                {title:"操作",align:"center",templet:function (data) {
                    return "<div>"
                        +"<a href='javascript:chakan("+data.trId+");' style='color: #2F4056;margin-right: 10px;'>查看</a>"
                        +"</div>";
                    }}
            ]]
        })
    };

    //搜索
    $('#sousuo').click(function () {
        var roleName = $('#roleName').val();
        var createDate = $('#createDate').val();
        var type = $("#type").val();

        selectJsApplicant(roleName,createDate,type);
    });
    //重置
    $('#reset').click(function () {
        location.reload();
    });

    //查看
    chakan = function chakan(trId) {
        $.ajax({
            type:"post",
            dataType:"json",
            data:{"id":trId},
            url:"/JsApplicant/selectApplicantById",
            success:function (data) {
                chakanLayer(data.data);
            }
        });
    };
    function chakanLayer(data){
        var obj;
        layer.open({
            type:2,
            shode:0,
            maxmin:true,
            title:"查看创作者信息",
            content:"/user/user-applicant-see.html",
            area:['600px','600px'],
            btn:["关闭"],
            yes:function (index) {
                layer.close(index);
            },success:function (layero,index) {
                obj = layero.find('iframe').contents();
                obj.find("#roleName").val(data.roleName);
                obj.find("#roleDescirbe").val(data.roleDescirbe);
                obj.find("#position").val(data.position);
                if(data.trueName==""||data.trueName==null){
                    var trueName = "未知";
                }else{
                    var trueName = data.trueName;
                }
                obj.find("#trueName").val(trueName);
                if(data.result=="1"){
                    var result = "待审核";
                }else if(data.result=="2"){
                    var result =  "已通过";
                }else{
                    var result =  "已驳回";
                }
                obj.find("#result").val(result);
                obj.find("#implementDate").val(data.implementDate);
            }
        })
    };

    //刷新
    $('#shuaxin').click(function () {
        location.reload();
    });

    //返回
    $("#goBack").click(function (s) {
        parent.$('#Jump').val('首页');
        parent.getQuick();
        return;
    });
});